package com.zf.easyexcel.controller;

import com.zf.easyexcel.utils.ExcelToZipUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Zhou Feng
 */
@RestController
@RequestMapping("/zip")
public class ExcelToZipController {

    /**
     * 导出多个 excel, 放入到一个zip中
     */
    @GetMapping("/multiExportToZip")
    public void multiExportToZip(HttpServletResponse response) throws IOException {
        ArrayList<String> multiExcelNameList = new ArrayList<>();
        ArrayList<byte[]> multiExcelByteList = new ArrayList<>();

        // 创建测试 excel
        for (int i = 0; i < 4; i++) {
            multiExcelNameList.add("test" + i + ".xlsx");
            multiExcelByteList.add(ExcelToZipUtils.getOneTestExcelByteArray());
        }
        // 生成的zip,并写入响应中
        ExcelToZipUtils.exportMultiExcelToZip("测试压缩", response, multiExcelNameList, multiExcelByteList);
    }

}
